// scalaxx - Scala XML eXtensions
// (c) 2009, Normen Müller, normen.mueller@gmail.com
// $Id: Commands.scala 50 2009-11-12 11:37:31Z normen.mueller $
package scalaxx.diff

import scala.xml.{Node, MetaData}

import scalaxx.path._

/**
 * Note: At current state, command paths are restricted to XPath 1.0. location paths.
 * 
 * @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
 * @version 0.0.2 */
sealed abstract class Command {
  def prefix: String
  val path: LocationPath
  val instruction: Seq[Instruction]
  
  override def toString(): String = prefix+"("+path+", " + (instruction mkString) + ")"
}

case class append(val path: LocationPath, val instruction: Instruction*) extends Command { def prefix: String = "append" }
case class remove(val path: LocationPath, val instruction: Instruction*) extends Command { def prefix: String = "remove" }
case class update(val path: LocationPath, val instruction: Instruction*) extends Command { def prefix: String = "update" }
case class before(val path: LocationPath, val instruction: Instruction*) extends Command { def prefix: String = "insert-before" }

/**
 * @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
 * @version 0.0.2 */
abstract class Instruction

case class elem(e: Seq[Node]) extends Instruction { override def toString(): String = e mkString }
case class attr(e: MetaData) extends Instruction  { override def toString(): String = e mkString }

